import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import s_get from '@dfeidao/atom-web/storage/get';
import a003 from './a003';

// import { spaceid } from './config';
export default async function a002(fd: IFeidaoAiBrowserComponent, args: { currentTarget: HTMLElement }) {
	// 确定按钮
	const c_boxs = fd.data.node.querySelectorAll('[data-feidao-name="list_checkbox"]:checked');
	fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="checkall"]').checked = false;
	if (c_boxs.length === 0) {
		error('请先选中至少一条数据');
		return;
	}
	const agarr = Array.from(c_boxs).map((v) => {
		return {
			field: v.getAttribute('field'),
			fieldtitle: v.getAttribute('fieldtitle'),
			fieldtype: v.getAttribute('fieldtype')

		};
	});
	const role_type_id = get(fd, 'role_type_id');
	const prid = await s_get('productid');

	const res = await nodejs('role-type/zj-000007/s002', { agarr, productid: prid, role_type_id });
	if (res === 'success') {
		success('新增成功');
		await a003(fd);
		fire('zj-000004', 'a007', 'tab3');
	} else {
		error('新增失败');
	}
}
